import 'package:flutter/material.dart';
import 'package:wallpaper/components/appbar_base.dart';
import 'package:wallpaper/components/button/normal_button.dart';
import 'package:wallpaper/components/input/normal_input.dart';
import 'package:wallpaper/components/input/password_input.dart';

class Login extends StatefulWidget {
  const Login({super.key});

  @override
  State<Login> createState() => _LoginState();
}

class _LoginState extends State<Login> {
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  final TextEditingController _unameController = TextEditingController();
  final TextEditingController _pwdController = TextEditingController();
  bool pwdShow = false;
  double interval = 20;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppbarBase(title: ''),
      body: Center(
        child: Container(
          padding: EdgeInsets.all(20),
          decoration: BoxDecoration(
              color: Theme.of(context).colorScheme.primaryContainer,
              gradient: LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [
                  Theme.of(context).colorScheme.primaryContainer,
                  Theme.of(context).colorScheme.secondary,
                ],
              )),
          child: _buildForm(),
        ),
      ),
    );
  }

  Widget _buildForm() {
    return Form(
      key: _formKey,
      autovalidateMode: AutovalidateMode.onUserInteraction,
      child: Flex(
        direction: Axis.vertical,
        mainAxisAlignment: MainAxisAlignment.start,
        spacing: 20,
        children: [
          SizedBox(height: 50),
          Text(
            '登录/注册',
            style: TextStyle(
              fontSize: 25,
              fontWeight: FontWeight.bold,
            ),
          ),
          NormalInput(
            controller: _unameController,
            icon: Icon(Icons.person),
            title: '用户名',
          ),
          PasswordInput(
            controller: _pwdController,
            title: '密码',
          ),
          NormalButton(
            title: '登录',
            onPressed: () {},
          ),
          Text('没有账号？去注册'),
          NormalButton(
            bgColor: Colors.white,
            textColor: Colors.black,
            title: '注册',
            onPressed: () {},
          ),
        ],
      ),
    );
  }
}
